#include <vector>
#include <string>
#include <unordered_map>
#include <iostream>
#include <time.h>
using namespace std;
class Solution
{
public:
    inline bool is_true(unordered_map<char, int> &frog)
    {
        return frog['c'] >= frog['r'] && frog['r'] >= frog['o'] && frog['o'] >= frog['a'] && frog['a'] >= frog['k'];
    }
    int minNumberOfFrogs(string croakOfFrogs)
    {
        unordered_map<char, int> frog;
        string croak = "croak";
        for (auto e : croak)
            frog[e] = 0;
        int now = 0, ans = 0;
        for (auto e : croakOfFrogs)
        {
            if (frog.count(e) == 0)
                return -1;
            frog[e]++;
            if (!is_true(frog))
                return -1;
            if (e == 'c')
                ans = max(ans, ++now);
            else if (e == 'k')
                --now;
        }
        int num_f = frog['c'];
        for (auto [c, x] : frog)
            if (x != num_f)
                return -1;
        return ans;
    }
};